package com.zhu.classpath.entry.base;

import java.io.File;
import java.io.InputStream;
//class文件提取器
abstract  class BaseEntry implements Entry{
    protected String absPath;
    /**
     * 构造 Entry 并规范化路径
     *
     * @param path 路径字符串
     */
    public BaseEntry(String path) {
        File file = new File(path);
        try {
            // 推荐：更规范
            this.absPath = file.getCanonicalPath();
        } catch (Exception e) {
            // 降级使用
            this.absPath = file.getAbsolutePath();
        }
    }

    /**
     * 所有 Entry 的默认 toString 返回其路径
     */
    @Override
    public String toString() {
        return this.absPath;
    }

    /**
     * 子类必须实现 readClass
     */
    @Override
    public abstract InputStream readClass(String className);
}
